package com.rainbow.gray.framework.starter.configuration.strategy;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.netflix.ribbon.RibbonClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.rainbow.gray.framework.adapter.strategy.DefaultStrategyVersionFilterAdapter;
import com.rainbow.gray.framework.adapter.strategy.StrategyVersionFilterAdapter;
import com.rainbow.gray.framework.constant.StrategyConstant;
import com.rainbow.gray.framework.filter.strategy.StrategyVersionFilter;
import com.rainbow.gray.framework.matcher.DiscoveryAntPathMatcherStrategy;
import com.rainbow.gray.framework.matcher.DiscoveryMatcherStrategy;

@Configuration
@RibbonClients(defaultConfiguration = { StrategyLoadBalanceConfiguration.class })
@ConditionalOnProperty(value = StrategyConstant.SPRING_APPLICATION_STRATEGY_CONTROL_ENABLED, matchIfMissing = true)
public class StrategyAutoConfiguration {
    @Bean
    @ConditionalOnMissingBean
    public DiscoveryMatcherStrategy discoveryMatcherStrategy() {
        return new DiscoveryAntPathMatcherStrategy();
    }

    @Bean
    @ConditionalOnMissingBean
    public StrategyVersionFilter strategyVersionFilter() {
        return new StrategyVersionFilter();
    }

    @Bean
    @ConditionalOnMissingBean
    public StrategyVersionFilterAdapter strategyVersionFilterAdapter() {
        return new DefaultStrategyVersionFilterAdapter();
    }

}